package com.lighting.smssystem.service.impl;

import com.github.qcloudsms.SmsMultiSender;
import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;
import com.lighting.smssystem.model.Template;
import com.lighting.smssystem.service.ISmsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author leemaster
 * @Title: TencentSmsService
 * @Package com.lighting.smssystem.service.impl
 * @Description:
 * @date 2019-06-0416:19
 */
@Service
@Slf4j
public class TencentSmsService implements ISmsService {

    @Resource
    SmsMultiSender multiSender;

    @Resource
    SmsSingleSender singleSender;

    @Value("${sms.tencent.sms.smsSign")
    public String smsSign;


    @Override
    public void sendSingleSms(Template template, Map<String, String> params, String phone) throws HTTPException, IOException {
        ArrayList<String> list = params.keySet().stream()
                .sorted(Comparator.comparingInt(Integer::parseInt))
                .map(params::get)
                .collect(Collectors.toCollection(ArrayList::new));
        System.out.println("发送短信");
//        SmsSingleSenderResult result = singleSender
//                .sendWithParam("86", phone, template.getTemplateExtId(), list, smsSign, Strings.EMPTY, Strings.EMPTY);
//        System.out.println(result);
    }

    @Override
    public void sendSingleSms(String content, String phone) throws HTTPException, IOException {
        singleSender.send(0,"86",phone,content, Strings.EMPTY,Strings.EMPTY);
    }

    @Override
    public void sendMultiSms(Template template, Map<String, String> params, String[] phones) throws HTTPException, IOException {
        ArrayList<String> list = params.keySet().stream()
                .sorted(Comparator.comparingInt(Integer::parseInt))
                .map(params::get)
                .collect(Collectors.toCollection(ArrayList::new));
//        multiSender
//                .sendWithParam("86", new ArrayList<>(Arrays.asList(phones)), template.getTemplateExtId(), list, Strings.EMPTY, Strings.EMPTY, Strings.EMPTY);
//
    }

    @Override
    public void sendMultiSms(String content, String[] phones) throws HTTPException, IOException {
        multiSender.send(0,"86",phones,content,Strings.EMPTY,Strings.EMPTY);
    }
}
